# ---------------------------------------------------------------------- #
# Copyright (c) 2024-2025 [XD-AMCC TEAM]
# [XD-AMCC] is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#          http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# ---------------------------------------------------------------------- #


#
# This file is included by ../CMakeLists.txt
#


include (../CMake.utils.txt)

# Initialized by the CFLAGS environment variable
if ( gcc STREQUAL  CMAKE_C_COMPILER )
    set(CMAKE_C_FLAGS "-Wno-unused-function -Wall")
    if (ENABLE_ASAN)
        message(STATUS "build with ASAN")
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
    endif ()
endif ()

# targetName of my library
set(LIB_AMCC    libamcc)

# core modules as a library
include_directories(libamcc/include)

file(GLOB_RECURSE  libamcc_h     libamcc/*.h)
file(GLOB_RECURSE  libamcc_h_inc libamcc/*.inc)
file(GLOB_RECURSE  libamcc_c     libamcc/*.c)

add_library(${LIB_AMCC} STATIC ${libamcc_c} ${libamcc_h} ${libamcc_h_inc})
if ( gcc STREQUAL  CMAKE_C_COMPILER )
    redefine_file_macro(${LIB_AMCC})
endif ()


add_compile_definitions(RECOGNIZE_TOKEN_STYLE=1)

# output file name is libamcc.a(gcc) or amcc.lib(VC)
set_target_properties(${LIB_AMCC} PROPERTIES
        OUTPUT_NAME                       "amcc"
        ARCHIVE_OUTPUT_DIRECTORY          ${MY_LIB_PATH}
        ARCHIVE_OUTPUT_DIRECTORY_DEBUG    ${MY_LIB_PATH}/DEBUG
        ARCHIVE_OUTPUT_DIRECTORY_RELEASE  ${MY_LIB_PATH}/RELEASE
)


#tell following EXE, find library files from here:
link_directories(${LIBRARY_OUTPUT_DIRECTORY})


#
# AMCC main
#

set(EXE_AMCC    amcc)

file(GLOB_RECURSE  amcc_main_c     main/*.c)
file(GLOB_RECURSE  amcc_main_h     main/*.h)

add_executable(${EXE_AMCC}  ${amcc_main_c} ${amcc_main_h})
if ( gcc STREQUAL  CMAKE_C_COMPILER )
    redefine_file_macro(${EXE_AMCC})
endif ()

target_link_libraries(${EXE_AMCC}  ${LIB_AMCC})
add_dependencies(${EXE_AMCC} ${LIB_AMCC})
set_target_properties(${EXE_AMCC} PROPERTIES
       RUNTIME_OUTPUT_DIRECTORY          ${MY_EXE_PATH}
       RUNTIME_OUTPUT_DIRECTORY_DEBUG    ${MY_EXE_PATH}/DEBUG
       RUNTIME_OUTPUT_DIRECTORY_RELEASE  ${MY_EXE_PATH}/RELEASE
)
